package com.sgb.member.util;

import android.text.TextUtils;

import androidx.annotation.IntDef;

import com.swgk.core.util.DateUtils;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

/**
 * @author: 杨畔
 * @date: 2021/1/22 12:25
 * @Description: 货物常量
 */
public class MCargoConstant {

    /**
     * 获取装卸方式
     */
    public static String getLoadMode(String loadMode) {
        if (loadMode == null) return "";
        String loadModeStr = "";
        switch (loadMode) {
            case "11":
                loadModeStr = "一装一卸";
                break;
            case "12":
                loadModeStr = "一装两卸";
                break;
            case "21":
                loadModeStr = "两装一卸";
                break;
            case "22":
                loadModeStr = "两装两卸";
                break;
        }
        return loadModeStr;
    }

    /**2.0.9版本跟后台沟通为字符串（不开发票）或者int（123）
     * 获取发票类型
     */
    public static String getInvoiceStr(String invoice) {
        if (invoice == null) return "";
        String invoiceStr = invoice;
        switch (invoice) {
            case "1":
                invoiceStr = "不开发票";
                break;
            case "2":
                invoiceStr = "普通发票";
                break;
            case "3":
                invoiceStr = "增值税专用发票";
                break;
        }
        return invoiceStr;
    }

    /**
     * 获取议价信息
     */
    public static String getBargainStr(Integer bargain) {
        if (bargain == null) return "";
        return bargain == 1 ? "可议价" : "不可议价";
    }

    /**
     * 获取装车要求
     */
    public static String getLoadRequire(int mode) {
        //装车要求： 1运方装车,2业主装车,3商议
        if (mode == 0) return "";
        String loadModeStr = "";
        switch (mode) {
            case 1:
                loadModeStr = "运方装卸";
                break;
            case 2:
                loadModeStr = "业主装卸";
                break;
            case 3:
                loadModeStr = "商议";
                break;
        }
        return loadModeStr;
    }

    /**
     * 获取承运类型
     */
    public static String getCarriageType(Integer type) {
        //卸车要求：1运方卸车,2业主卸车,3商议
        if (type == null || type == 0) return "";
        String str = "";
        switch (type) {
            case 1:
                str = "普通承运";
                break;
            case 2:
                str = "竞价承运";
                break;
            case 3:
                str = "特价承运";
                break;
        }
        return str;
    }

    /**
     * 格式化时间戳为选择装货时间展示规范  yyyy/mm/dd hh时
     */
    public static String stampFormatLoadInput(Long time, Integer point) {
        if (time == null || time == 0) {
            return "";
        }
        String date = DateUtils.formatDate(time, "yyyy/MM/dd");
        return String.format("%s %s", date, point == null || point == 0 || point == 25 ? "全天" : String.format("%s点", point));
    }

    /**
     * 格式化时间戳为装货时间展示规范  mm/dd hh点
     */
    public static String stampFormatLoad(Long time, Integer point) {
        return stampFormatLoad(false, time, point);
    }

    public static String stampFormatLoad(boolean isNeedYear, Long time, Integer point) {
        if (time == null || time == 0) {
            return "";
        }
        String date = DateUtils.formatDate(time, isNeedYear ? "yyyy/MM/dd" : "MM/dd");
        return String.format("%s %s", date, point == null || point == 0 || point == 25 ? "全天" : String.format("%s点", point));
    }

    /**
     * 格式化时间戳为装货时间展示规范  mm月dd日 hh点
     */
    public static String stampFormatLoadText(Long time, Integer point) {
        return stampFormatLoadText(false, time, point);
    }

    public static String stampFormatLoadText(boolean isNeedYear, Long time, Integer point) {
        if (time == null || time == 0) {
            return "";
        }
        String date = DateUtils.formatDate(time, isNeedYear ? "yyyy年MM月dd日" : "MM月dd日");
        return String.format("%s%s", date, point == null || point == 0 || point == 25 ? "全天" : String.format("%s点", point));
    }

    /**
     * 格式化列表装货时间展示
     */
    public static String stampFormatListLoadTime(Long startTime, Integer startPoint, Long endTime, Integer endPoint) {
        return stampFormatListLoadTime(false, startTime, startPoint, endTime, endPoint);
    }

    public static String stampFormatListLoadTime(boolean isNeedYear, Long startTime, Integer startPoint, Long endTime, Integer endPoint) {
        String begin = stampFormatLoad(isNeedYear, startTime, startPoint);
        String end = stampFormatLoad(isNeedYear, endTime, endPoint);
        if (TextUtils.isEmpty(end) || begin.equals(end)) {
            return begin;
        } else {
            return String.format("%s - %s", begin, end);
        }
    }

    public static String stampFormatListLoadTime(Long startTime, Long endTime) {
        String begin = DateUtils.stampToDay5(startTime);
        String end = DateUtils.stampToDay5(endTime);
        String lastBegin = DateUtils.stampToDay4(startTime);
        String lastEnd = DateUtils.stampToDay4(endTime);
        if (TextUtils.isEmpty(end) || begin.equals(end)) {
            return lastBegin;
        } else {
            return String.format("%s - %s", lastBegin, lastEnd);
        }
    }

    /**
     * 获取用车类型
     */
    public static String getTransportTypeStr(Integer type) {
        //用车类型 0 零担 1 整车
        if (type == null) return "整车";
        String str = "";
        switch (type) {
            case 0:
                str = "零担";
                break;
            case 1:
                str = "整车";
                break;
        }
        return str;
    }

    /**
     * 普通货源货源状态
     */
    @IntDef({MCargoConstant.NormalCargoMode.MODE_PENDING_ORDER,
            MCargoConstant.NormalCargoMode.MODE_DEAL_DOWN,
            MCargoConstant.NormalCargoMode.MODE_EXPIRED,
            MCargoConstant.NormalCargoMode.MODE_PAYING,
            MCargoConstant.NormalCargoMode.MODE_DOWN})
    @Retention(RetentionPolicy.SOURCE)
    public @interface NormalCargoMode {
        //普通货源状态 0 待接单  1 已成交  2 已失效  3 付款中 5 已下架
        int MODE_PENDING_ORDER = 0;//待接单
        int MODE_DEAL_DOWN = 1;//已成交
        int MODE_EXPIRED = 2;//已失效
        int MODE_PAYING = 3;//冻结(付款中)
        int MODE_DOWN = 5;//已下架
    }

    /**
     * 竞价货源货源状态
     */
    @IntDef({MCargoConstant.BiddingCargoMode.MODE_BIDDING,
            MCargoConstant.BiddingCargoMode.MODE_DEAL_DOWN,
            MCargoConstant.BiddingCargoMode.MODE_EXPIRED,
            MCargoConstant.BiddingCargoMode.MODE_DEADLINE,
            MCargoConstant.BiddingCargoMode.MODE_DOWN})
    @Retention(RetentionPolicy.SOURCE)
    public @interface BiddingCargoMode {
        //竞价货源状态 0 竞价中  1 已成交  2 已失效  4 报价已截止 5 已下架
        int MODE_BIDDING = 0;//竞价中
        int MODE_DEAL_DOWN = 1;//已成交
        int MODE_EXPIRED = 2;//已失效
        int MODE_DEADLINE = 4;//报价已截止
        int MODE_DOWN = 5;//已下架
    }
}
